package com.rd.teacher.jichao.day12;

public class TestJoinMills extends Thread {

    public TestJoinMills(String name) {
        super(name);
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        for (int i = 0; i < 50; i++) {
            System.out.println(getName() + " " + i);
        }
    }

    public static void main(String[] args) throws Exception {
//        new TestJoin("Thread11").start();
        for (int i = 0; i < 50; i++) {

            if (i == 20) {
                TestJoinMills thread22 = new TestJoinMills("Thread22");
                thread22.start();
                // main的主线程中调用了 thread22线程的join()方法
                // 需要等待此线程结束后才能继续执行
                thread22.join(300);
            }

            System.out.println(Thread.currentThread().getName()
                    + " " + i);
        }
    }
}
